package com.xianyun.book.controller;

import com.alibaba.cola.dto.MultiResponse;
import com.alibaba.cola.dto.Response;
import com.alibaba.cola.dto.SingleResponse;
import com.xianyun.book.api.BookServiceI;
import com.xianyun.book.dto.BookUpdateCmd;
import com.xianyun.book.dto.clientobject.BookInfoCO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 书籍域
 * 书籍的综合查询 喜爱书籍推送 详情 评价 等
 * @author ytt
 */
@CrossOrigin
@RestController
public class BookController {

    @Autowired
    private BookServiceI bookService;


    /**
     * 修改书籍
     * @return 请求结果
     */
    @PostMapping("/book/refresh")
    public Response refreshBook(@RequestBody BookUpdateCmd updateCmd){
        return bookService.refreshBookInfo(updateCmd);
    }

    /**
     * 根据书籍标签查询书籍集合
     * @param tag 书籍标签
     * @return 请求结果
     */
    @GetMapping("/open/book/query/tag/{tag}")
    public MultiResponse<BookInfoCO> queryBooksByTag(@PathVariable String tag){
        return bookService.searchBooksByTag(tag);
    }

    /**
     * 根据ISBN查询并保存书籍详情
     * @return 请求结果
     */
    @GetMapping("/open/book/info/{bookIsbn}")
    public SingleResponse<BookInfoCO> getBookInfo(@PathVariable String bookIsbn){
        return bookService.getBookInfoByIsbn(bookIsbn);
    }
}
